﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace Apq.Security.Cryptography
{
	/// <summary>
	/// MD5Helper
	/// </summary>
	public class MD5Helper
	{
		/*
		#region 文件处理
		/// <summary>
		/// 加密文件
		/// </summary>
		/// <param name="inName">来源文件</param>
		/// <param name="outName">输出文件</param>
		/// <param name="desKey">加密密钥</param>
		/// <param name="desIV">初始向量</param>
		public static void EncryptFile(string inName, string outName, byte[] desKey, byte[] desIV)
		{
			DES des = DES.Create();
			des.Key = FormatKey(desKey);
			des.IV = FormatKey(desIV);
			SymmetricAlgorithmHelper.EncryptFile(inName, outName, des);
		}

		/// <summary>
		/// 解密文件
		/// </summary>
		/// <param name="inName">来源文件</param>
		/// <param name="outName">输出文件</param>
		/// <param name="desKey">解密密钥</param>
		/// <param name="desIV">初始向量</param>
		public static void DecryptFile(string inName, string outName, byte[] desKey, byte[] desIV)
		{
			DES des = DES.Create();
			des.Key = FormatKey(desKey);
			des.IV = FormatKey(desIV);
			SymmetricAlgorithmHelper.DecryptFile(inName, outName, des);
		}
		#endregion
		*/

		#region 字符串处理
		/// <summary>
		/// 加密字符串
		/// </summary>
		/// <param name="PlainText">原始字符串</param>
		/// <returns>MD5串(16进制)</returns>
		public static string EncryptString(string PlainText)
		{
			MD5 md5 = MD5.Create();
			byte[] bin = Encoding.Default.GetBytes(PlainText);
			byte[] binMD5 = md5.ComputeHash(bin);
			string strRtn = Apq.Convert.BytesToHexString(binMD5);
			return strRtn;
		}
		#endregion
	}
}
